#
# AS - C++ Application server
#
PROJECT(cas)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)

# ################################################################################
# Macroses
#

# Standard CMake macroses
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckLibraryExists)
INCLUDE(FindZLIB)

# User-defined macroses
INCLUDE(cmake/ConfigureLibrary.cmake)
INCLUDE(cmake/ConfigurePackage.cmake)
INCLUDE(cmake/RenameModule.cmake)

# ################################################################################
# Version
#
SET(AS_MEMC_VERSION_MAJOR 3)
SET(AS_MEMC_VERSION_MINOR 7)
SET(AS_MEMC_VERSION_PATCH 1)

SET(AS_MEMC_VERSION       "${AS_MEMC_VERSION_MAJOR}.${AS_MEMC_VERSION_MINOR}.${AS_MEMC_VERSION_PATCH}")

# ################################################################################
# Set system-specific data
#
MESSAGE(STATUS "#### System name is: ${CMAKE_SYSTEM_NAME}")

# ################################################################################
# Setup libraries & headers
#

#
# Configure CTPP2 package
#
CONFIGURE_PACKAGE(ctpp2-config ctpp2 CTPP2)

#
# Configure CAS package
#
CONFIGURE_PACKAGE(cas-config cas CAS)

INCLUDE_DIRECTORIES(include)


SET(ZLIB_INCLUDE_DIR /usr/include /usr/local/include)

# ################################################################################
# Lib binary
#
SET(CMAKE_CXX_FLAGS " -g ")
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
	SET(CMAKE_CXX_FLAGS " -g -Werror")
ENDIF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")

ADD_LIBRARY(casmemcached SHARED src/ASMemcachedObject.cpp src/ASMemcached.cpp)
SET_TARGET_PROPERTIES(casmemcached PROPERTIES OUTPUT_NAME casmemcached)
SET_TARGET_PROPERTIES(casmemcached PROPERTIES LINKER_LANGUAGE CXX)
SET_TARGET_PROPERTIES(casmemcached PROPERTIES VERSION ${AS_MEMC_VERSION} SOVERSION ${AS_MEMC_VERSION_MAJOR}.${AS_MEMC_VERSION_MINOR})
TARGET_LINK_LIBRARIES(casmemcached ${HAVE_ctpp2} ${HAVE_cas} ${ZLIB_LIBRARIES})

ADD_LIBRARY(mod_memcached_module MODULE src/ASMemcachedConnector.cpp)
TARGET_LINK_LIBRARIES(mod_memcached_module casmemcached)
RENAME_MODULE(mod_memcached_module mod_memcached_module)

ADD_LIBRARY(mod_memcached_test MODULE src/ASMemcachedTest.cpp)
TARGET_LINK_LIBRARIES(mod_memcached_test casmemcached)
RENAME_MODULE(mod_memcached_test mod_memcached_test)

ADD_EXECUTABLE(test-memcached tests/MemcachedTest.cpp)
TARGET_LINK_LIBRARIES(test-memcached casmemcached)

ADD_EXECUTABLE(test-hash tests/ConsistentHash.cpp)
TARGET_LINK_LIBRARIES(test-hash casmemcached)

# ################################################################################
# Install library headers
#
INSTALL(FILES include/ASMemcachedObject.hpp
              include/ASMemcached.hpp
              include/ASConsistentHash.hpp
        DESTINATION include/cas/modules
        PERMISSIONS OWNER_READ OWNER_WRITE
                    GROUP_READ
                    WORLD_READ)

# ################################################################################
# Install library
#
INSTALL(TARGETS casmemcached DESTINATION lib)

# ################################################################################
# Install modules
#
INSTALL(FILES mod_memcached_module.so mod_memcached_test.so
        DESTINATION libexec/cas
        PERMISSIONS OWNER_READ OWNER_WRITE
                    GROUP_READ
                    WORLD_READ)

# End.
